package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Scanner;

public class JDBCDemo8 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection();) {
            String sql = "INSERT INTO user(username,password,nickname,age )"+
                    "VALUES(?,?,?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
            Scanner scan = new Scanner(System.in);
            String name = scan.nextLine();
            String password = scan.nextLine();
            String nickname = scan.nextLine();
            int age = scan.nextInt();
            ps.setString(1,name);
            ps.setString(2,password);
            ps.setString(3,nickname);
            ps.setInt(4,age);
            int count = ps.executeUpdate();
            if(count>0){
                System.out.println("添加成功");
            }else {
                System.out.println("添加失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
